package codeForce;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StreamTokenizer;
import java.util.ArrayList;

public class B_Spreadsheets {

    public static void main(String[] args) throws IOException {
        StreamTokenizer st=new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        st.nextToken();
        ArrayList<String> ot=new ArrayList<>();
        long n=(long)st.nval;
        for (int i = 0; i < n; i++) {
            StringBuilder output=new StringBuilder();
            st.nextToken();
            String str=st.sval;
            int index=0;
            boolean b1=true;
            boolean b2=false;
            //判断是类型1还是类型2
            for(int j = 0; j < str.length(); j++) {
                if(b1&&str.charAt(j)>='0'&&str.charAt(j)<='9'){
                    b1=false;
                }
                if(!b1&&!(str.charAt(j)>='0'&&str.charAt(j)<='9')){
                    b2=true;
                    break;
                }
            }
            //类型2
            if(b2){
                int iTmp=1;
                while(str.charAt(iTmp)!='C'){
                    iTmp++;
                }
                int num1=Integer.parseInt(str.substring(1,iTmp));
                iTmp++;
                int num2=Integer.parseInt(str.substring(iTmp));
                int n1=1;
                int tmp2=num2;
                while(tmp2>0){
                    tmp2=tmp2-(int)Math.pow(26,n1);
                    n1++;
                }
                n1-=2;
                for (int l = n1; l >= 0; l--) {
                    int tmp=(int) (Math.pow(26, l));
                    if(num2/tmp>26){
                        output.append("Z");
                        index++;
                        num2-=tmp*26;
                    }else{
                        if((num2%tmp==0&&tmp!=1&&(num2/tmp!=1))){
                            char ch=(char)('A'+(num2/tmp)-1-1);
                            output.append(ch);
                            index++;
                            num2-=tmp*((num2/tmp)-1);
                        }else{
                            if(num2<tmp){
                                int tmpIndex=index;
                                while(true){
                                    char ch=output.charAt(tmpIndex-1);
                                    output.deleteCharAt(tmpIndex-1);
                                    if((char)(ch-1)<'A') {
                                        tmpIndex--;
                                        num2 += (int) Math.pow(26, l + 1);
                                        l++;
                                    }else{
                                        output.append((char)(ch-1));
                                        num2+=(int)Math.pow(26,l+1);
                                        break;
                                    }
                                }
                                l++;
                                continue;
                            }
                            int tmp4=(num2 / tmp - 1);
                            char ch1 = (char) ('A' + tmp4);
                            output.append(ch1);
                            index++;
                            int tmp3=tmp*((num2 / tmp));
                            num2 = num2-tmp3;
                        }
                    }
                }
                output.append(num1);
                ot.add(output.toString());
            }else{
                int iTmp=0;
                int nTmp=0;
                while(str.charAt(iTmp)>='A'&&str.charAt(iTmp)<='Z'){
                    iTmp++;
                    nTmp++;
                }
                nTmp--;
                String str1=str.substring(0,iTmp);
                String num2=str.substring(iTmp);
                long num1=0;
                for (int l = 0; l <iTmp; l++) {
                    int tmp=(str1.charAt(l)-'A'+1)*(int)(Math.pow(26,nTmp--));
                    num1+=tmp;
                }
                output.append("R").append(num2).append("C").append(num1);
                ot.add(output.toString());
            }
        }
        for (String s : ot) {
            System.out.println(s);
        }
    }
}
